﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommonTools.Encrypt
{
    public class URL
    {
        /// <summary>
        /// Url加密
        /// </summary>
        /// <param name="str"></param>
        /// <param name="en"></param>
        /// <returns></returns>
        public static string UrlEncode(string str, Encoding en)
        {
            if (str.Trim().Equals("")) return str;
            var sb = new StringBuilder();
            byte[] byStr = en.GetBytes(str);
            foreach (var t in byStr)
            {
                sb.Append(@"%" + Convert.ToString(t, 16));
            }

            return (sb.ToString());
        }
    }
}
